package com.utils

import java.util.Properties

import org.apache.kudu.client.CreateTableOptions
import org.apache.kudu.spark.kudu.KuduContext
import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}
import org.apache.spark.sql.types.StructType

object KuduUtils {
  def writeToKudu(kuduContest:KuduContext,schema:StructType,
                  options:CreateTableOptions,tableName:String,keys:Seq[String],data:DataFrame)={
    if(!kuduContest.tableExists(tableName)){
      kuduContest.createTable(tableName,schema,keys,options)
    }
    kuduContest.upsertRows(data,tableName)
  }
  def writeToMysql(url:String,tableName:String,connectionProperties:Properties,data:DataFrame): Unit ={

    data.write.mode(SaveMode.Overwrite).jdbc(url,tableName,connectionProperties)

  }

}
